// 配置请求基地址
axios.defaults.baseURL = 'https://hmajax.itheima.net'

// 封装轻提示
function showToast(msg) {
  const myToast = document.querySelector('.my-toast')

  const toast = new bootstrap.Toast(myToast)
  document.querySelector('.toast-body').innerHTML = msg

  toast.show()
}

// 页面的控制权限
function checkLogin() {
  const token = localStorage.getItem('token')
  if (token === null) {
    showToast('请登录')
    setTimeout(function () {
      location.href = './login.html'
    }, 1500)
  }
}

// 用户名渲染
function yonghuming() {
  const username = localStorage.getItem('username')
  document.querySelector('.username').innerHTML = username
}

// 退出登录
function tuichudenglu() {
  const logout = document.querySelector('#logout')
  logout.addEventListener('click', function () {
    localStorage.removeItem('username')
    localStorage.removeItem('token')

    // 提示
    showToast('成功退出')
    setTimeout(function () {
      location.href = './login.html'
    }, 1500)
  })
}
